package com.lzp.copyui.main

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.DragEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.base.BaseFragment
import com.lzp.copyui.design.ShapeImageViewActivity
import com.lzp.copyui.R
import com.lzp.copyui.databinding.CopyuiFragmentBinding
import com.lzp.copyui.design.ShapeViewActivity
import com.lzp.copyui.draganddrop.DragShadow
import com.lzp.copyui.gallery.GalleryActivity
import com.lzp.copyui.ijk.GSYVideoPlayer
import com.lzp.copyui.message.MessageActivity
import com.lzp.copyui.motionlayout.MotionLayoutDemoActivity
import com.lzp.copyui.mvvmtest.MVVMTestActivity
import com.lzp.copyui.pvz.PVZActivity
import com.lzp.copyui.rv.RvMainActivity
import com.lzp.copyui.rv.SnapHelperActivity
import com.lzp.copyui.tabmanager.TabManagerActivity
import com.lzp.copyui.transition.CarActivity
import com.utils.LogUtils
import kotlinx.android.synthetic.main.copyui_fragment.*

/**
 * @describe:
 * @Author: lixiaopeng
 * @Date: 2020/3/24
 */
class CopyUiFragment : BaseFragment(), View.OnClickListener {

    private val binding: CopyuiFragmentBinding by lazy {
        CopyuiFragmentBinding.inflate(
            layoutInflater
        )
    }

    private val a by lazy {  }
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return binding.root
    }

    override fun setListener() {
        super.setListener()
        binding.switchMsgOpenTv.setOnClickListener(this)
        binding.transitionTv.setOnClickListener(this)
        binding.tabManagerTv.setOnClickListener(this)
        binding.galleryTv.setOnClickListener(this)
        binding.shapeImageViewTv.setOnClickListener(this)
        binding.shapeViewTv.setOnClickListener(this)
        binding.mvvmTv.setOnClickListener(this)
        binding.ijkPlayer.setOnClickListener(this)
        binding.rv.setOnClickListener(this)
        binding.motionLayout.setOnClickListener(this)
        binding.pvz.setOnClickListener(this)
        binding.dragAndDrop.setOnLongClickListener {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                binding.dragAndDrop.startDragAndDrop(null,
                   /* View.DragShadowBuilder(binding.dragAndDrop),*/
                    DragShadow(binding.dragAndDrop),
                    null,View.DRAG_FLAG_GLOBAL)


            }
            true
        }

        binding.root.setOnDragListener(object :View.OnDragListener{
            override fun onDrag(v: View?, event: DragEvent?): Boolean {
                when(event?.action){
                    DragEvent.ACTION_DRAG_STARTED->{
                        binding.root.alpha = 0.5f
                        val x = event.x
                        val y = event.y
                    }
                    DragEvent.ACTION_DROP->{
                        val x = event.x
                        LogUtils.d("ACTION_DROP = $x")
                    }
                    DragEvent.ACTION_DRAG_LOCATION->{
                        val x = event.x
                        LogUtils.d("ACTION_DRAG_LOCATION = $x")
                    }
                    DragEvent.ACTION_DRAG_ENDED->{
                        val x = event.x
                        binding.root.alpha = 1f
                        LogUtils.d("ACTION_DRAG_ENDED = $x")
                    }
                    DragEvent.ACTION_DRAG_ENTERED->{
                        LogUtils.d("ACTION_DRAG_ENTERED")
                    }
                    DragEvent.ACTION_DRAG_EXITED->{
                        LogUtils.d("ACTION_DRAG_EXITED")
                    }
                }
                return true
            }

        })
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.pvz->{
                val intent = Intent(activity, PVZActivity::class.java)
                startActivity(intent)
            }
            R.id.switchMsgOpenTv -> {
                val intent = Intent(activity, MessageActivity::class.java)
                startActivity(intent)
            }
            R.id.transitionTv -> {
                val intent = Intent(activity, CarActivity::class.java)
                startActivity(intent)
            }
            R.id.tabManagerTv -> {
                val intent = Intent(activity, TabManagerActivity::class.java)
                startActivity(intent)
            }
            R.id.galleryTv -> {
                val intent = Intent(activity, GalleryActivity::class.java)
                startActivity(intent)
            }
            R.id.shapeImageViewTv -> {
                val intent = Intent(activity, ShapeImageViewActivity::class.java)
                startActivity(intent)
            }
            R.id.shapeViewTv -> {
                val intent = Intent(activity, ShapeViewActivity::class.java)
                startActivity(intent)
            }

            R.id.mvvmTv -> {
                val intent = Intent(activity, MVVMTestActivity::class.java)
                startActivity(intent)
            }
            R.id.ijkPlayer -> {
                val intent = Intent(activity, GSYVideoPlayer::class.java)
                startActivity(intent)
            }
            R.id.rv -> {
                val intent = Intent(activity, RvMainActivity::class.java)
                startActivity(intent)
            }
            R.id.motionLayout -> {
                val intent = Intent(activity, MotionLayoutDemoActivity::class.java)
                startActivity(intent)
            }
        }
    }
}